﻿using AutoMapper;
using MediatR;
using S.Breeding.Api.Application.Command.SheepWeighCommand;
using S.Breeding.Domain;
using S.Breeding.Infrastructure;

namespace S.Breeding.Api.Application.CommandHandlers.SheepWeighCommandHandlers
{
    public class SheepWeighCreateCommandHandlers : IRequestHandler<SheepWeighCreateCommand, int>
    {
        private readonly IRepository<SheepWeigh> repository;
        private readonly IMapper mapper;
        public SheepWeighCreateCommandHandlers(IRepository<SheepWeigh> repository, IMapper mapper)
        {
            this.repository = repository;
            this.mapper = mapper;
        }

        public async Task<int> Handle(SheepWeighCreateCommand request, CancellationToken cancellationToken)
        {

            return await repository.CreateAsync(mapper.Map<SheepWeigh>(request));
        }
    }
}
